<?php
/*
Plugin Name: dKret About Widget
Description: Adds a Sidebar Widget to display information about the author.
Author: J. Kretzschmar
Version: 1.0
Author URI: http://diekretzschmars.de
*/

function widget_show_dkret_about($args) {
	extract($args);
	$options = get_option('widget_dkret_about');
	$title = empty($options['title']) ? __('About','dkret') : $options['title'];	
	global $user_ID; if (($user_ID) && ($options['login'] == 'checked="checked"')) return;
	echo "\t\t\t$before_widget\n";
		echo "\t\t\t\t$before_title".$title.$after_title;
		echo "\t\t\t\t<div class=\"dkret-about-widget\">\n";
		echo "\t\t\t\t\t" .stripslashes($options['abouttext']);
		echo "\n\t\t\t\t</div>";
	echo "\n\t\t\t$after_widget";
}

// Admin section
function widget_control_dkret_about() {
 	$options = $newoptions = get_option('widget_dkret_about');
	if ( $_POST["dkret-submit"] ) {
		$newoptions['title'] = strip_tags(stripslashes($_POST["dkret-about-title"]));
		$newoptions['abouttext'] = stripslashes($_POST['dkret-about-text']);
		$newoptions['login'] = isset($_POST['dkret-about-hide']);
	}
	if ( $options != $newoptions ) {
		$options = $newoptions;
		update_option('widget_dkret_about', $options);
	}
	
	$title = attribute_escape($options['title']);
	$hide = $options['login'] ? 'checked="checked"' : '';
	$abouttext = stripslashes($options['abouttext']);
	
	// The Box content
	echo '<p style="text-align:right;"><label for="dkret-about-title">' . __('Title:') . ' <input style="width: 300px;" id="dkret-about-title" name="dkret-about-title" type="text" value="'.$title.'" /></label></p>';
	echo '<p style="text-align:right;"><label for="dkret-about-hide">' . __('Hide About Widget if User is logged in:', 'dkret') . ' <input id="dkret-about-hide" name="dkret-about-hide" type="checkbox" '. $hide .'  /></label></p>';
	echo '<p style="text-align:right;"><label for="dkret-about-text">' . __('About Text:', 'dkret'). ' <textarea name="dkret-about-text" style="width: 300px;" rows="12" cols="20" id="dkret-about-text">' .$abouttext. '</textarea></label></p>';
	echo '<input type="hidden" id="dkret-submit" name="dkret-submit" value="1" />';
}

$options = get_option('widget_dkret_about');
if ( !is_array($options) )
	$options = array('login'=>'', 'abouttext'=>''. __('A little something about yourself', 'dkret') .'',);
	update_option('widget_dkret_about', $options);

$widget_ops = array('classname' => 'widget_dkret_about', 'description' => __( 'Add a little Something about yourself (dkret)', 'dkret' ) );
$control_ops = array('width' => 400, 'height' => 350, 'id_base' => 'text');
wp_register_sidebar_widget('about', __('About','dkret'), 'widget_show_dkret_about', $widget_ops);
wp_register_widget_control('about', __('About','dkret'), 'widget_control_dkret_about', $control_ops);
?>